package DynamicProgramingSeries;

import java.util.ArrayList;
import java.util.List;

public class GenerateSolution_118 {
    public List<List<Integer>> generate(int numRows) {
        List<List<Integer>> result = new ArrayList<>();

        for (int row = 0; row < numRows; row++) {
            // 得到每一行的值
            List<Integer> rowRes = new ArrayList<>();
            for (int col = 0; col < row + 1; col++) {
                int val = 0;
                if (col == 0 || col == row) {
                    val = 1;
                } else {
                    val = result.get(row - 1).get(col - 1) + result.get(row - 1).get(col);
                }
                rowRes.add(val);
            }
            result.add(rowRes);
        }
        return result;
    }
}
